package com.starry.module.system.core.logger.mapper;

import com.starry.core.common.domain.vo.PageVo;
import com.starry.core.tenant.core.aop.TenantIgnore;
import com.starry.db.core.mapper.BaseMapperX;
import com.starry.db.core.query.LambdaQueryWrapperX;
import com.starry.module.system.api.logger.domain.qo.SysLogOperationPageQo;
import com.starry.module.system.core.logger.entity.SysLogOperation;
import org.apache.ibatis.annotations.Mapper;

/**
 * 操作日志-数据库服务层
 * @author xiaoke
 */
@Mapper
public interface SysLogOperationMapper extends BaseMapperX<SysLogOperation> {

    /**
     * 分页查询
     *
     * @param pageQo 分页参数
     * @return PageVo<SysLogOperation>
     */
    @TenantIgnore
    default PageVo<SysLogOperation> selectPage(SysLogOperationPageQo pageQo) {
        return selectPage(pageQo, new LambdaQueryWrapperX<SysLogOperation>()
                .eqIfPresent(SysLogOperation::getOperId, pageQo.getOperId())
                .eqIfPresent(SysLogOperation::getApplicationName, pageQo.getApplicationName())
                .eqIfPresent(SysLogOperation::getBusinessType, pageQo.getBusinessType())
                .eqIfPresent(SysLogOperation::getUserType, pageQo.getUserType())
                .likeIfPresent(SysLogOperation::getTitle, pageQo.getTitle())
                .likeIfPresent(SysLogOperation::getRequestMethod, pageQo.getRequestMethod())
                .likeIfPresent(SysLogOperation::getRequestUrl, pageQo.getRequestUrl())
                .likeIfPresent(SysLogOperation::getRequestIp, pageQo.getRequestIp())
                .likeIfPresent(SysLogOperation::getOperatingSystem, pageQo.getOperatingSystem())
                .likeIfPresent(SysLogOperation::getBrowserType, pageQo.getBrowserType())
                .likeIfPresent(SysLogOperation::getIpAddress, pageQo.getIpAddress())
                .betweenIfPresent(SysLogOperation::getOperTime, pageQo.getOperTimeStart(), pageQo.getOperTimeEnd())
                .orderByDesc(SysLogOperation::getOperTime)
        );
    }
}

